﻿@{
    ViewBag.Title = "AdvManage";
    Layout = null;
}
@model List<UcAsp.Net.Model.AdvPositions>
<script type="text/javascript">
    tinymce.init({
        selector: "textarea",
        plugins: [
        "advlist autolink lists link image charmap print preview anchor",
        "searchreplace visualblocks code fullscreen",
        "insertdatetime media table contextmenu paste hr upfile"
        ],
        toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent |link image upfile"

    });
    $(function () {
        $("#addAdv").click(function () {
            var divObj = document.getElementById("row-content");
            
            var html="<div clsss=\"span12\">"
                + "<div class=\"span10\">"
                   + "<div class=\"control-group\">"
                   + "<label class=\"control-label\">广告名称</label>"
                   + "<div class=\"controls\">"
                     + "<input class=\"text-input small-input\" type=\"text\" name=\"AdvChinaName\"  value=\"\" />"
                    + "</div>"
                + "</div>"
                + "<div class=\"control-group\">"
                   + "<label class=\"control-label\">内容</label>"
                   + "<div class=\"controls\">"
                     + "<textarea class=\"text-input textarea wysiwyg\"  name=\"AdvContent\" cols=\"79\" rows=\"5\"></textarea>"
                    + "</div>"
                + "</div>"
            + "</div>"
            + "<div class=\"span2\">"
             + "<div class=\"btn saveadv\" data-cid=\"@ViewData["Id"]\" data-id=\"new\">保存</div>"
            + "</div></div>"
            divObj.innerHTML+=html;


            tinymce.init({
                selector: "textarea",
                plugins: [
                "advlist autolink lists link image charmap print preview anchor",
                "searchreplace visualblocks code fullscreen",
                "insertdatetime media table contextmenu paste hr upfile"
                ],
                toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent |link image upfile"

            });
        });
        $(".saveadv").live("click",function () {
            var adv = $(this).attr("data-id");
            var cid = $(this).attr("data-cid");
            console.log($("input[name='AdvChinaName']").val());
            var html;
            if (adv == "new") {
                adv = $("input[name='AdvChinaName']").val();
                html = tinyMCE.get("AdvContent").getContent();
            }
            else {
                html = tinyMCE.get(adv).getContent();
            }

            $.post("/admin/SaveAdv", { Theme: $("input[name='theme']").val(), AdvHtml: html, AdvChinaName: adv, AdvPositionName: adv, CId: cid @if (Request["Message"] != null)
                                                                                                                                                                        {<text>, Message: 'show'</text>}  }, function () {
                alert("保存完毕")
            })
        })
    })

</script>
<span class="btn" id="addAdv">添加</span>
<div class="widget-box">

    <div class="widget-title">

        <span class="icon"><i class="icon-align-justify"></i></span>
        <h5>广告位管理</h5>
        <input type="hidden" name="theme" value="@Request["Theme"].ToString()"/>
    </div>
    <div class="widget-content nopadding">
        <form action="#" method="get" class="form-horizontal">
            <div id="row-content" class="row-fluid">
                @foreach (UcAsp.Net.Model.AdvPositions adv in Model)
                {
                    <div class="span12">
                        <div class="span10">
                            <div class="control-group">
                                <label class="control-label">
                                    @adv.AdvPositionName</label>
                                <div class="controls">
                                    <textarea class="text-input textarea wysiwyg"  name="@adv.AdvPositionName" cols="79" rows="5">@adv.AdvHtml</textarea>
                                </div>
                            </div>
                        </div>
                        <div class="span2">
                            <div class="btn saveadv" data-cid="@ViewData["Id"]" data-id="@adv.AdvPositionName">保存</div>
                        </div>
                    </div>
                }
            </div>
        </form>
    </div>
</div>
